﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HandicapsApp;
using System.Data.OleDb;
using System.Data.SqlClient;      // For the database connections and objects.

namespace ProjectHandicap
{

    public partial class newClient : Form
    {
        string Nom;
        string Societe;
        string Adresse;
        string Tel;
        string Pass;
        string Contrat;


        public newClient()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string guid = "16814dbd-832b-463d-9f3a-15afa2ac42d2";

            #region tests
            //DataSet ds = new DataSet();

            //DataSet Bdd_Handicap_DataDataSet;
            //Bdd_Handicap_DataDataSet = new DataSet();


            //        Bdd_Handicap_DataDataSet.handicap_CustomerRow newhandicap_CustomerRow =
            //Bdd_Handicap_DataDataSet.handicap_Customer.Newhandicap_CustomerRow();

            //        newhandicap_CustomerRow.Customer_ID = guid;
            //        newhandicap_CustomerRow.Customer_Company = "Alfreds Futterkiste";

            //        Bdd_Handicap_DataDataSet.handicap_Customer.Rows.Add(newhandicap_CustomerRow);

            //// Chaîne de connexion à la base de donnée
            //String cnxStr = System.Configuration.ConfigurationManager.ConnectionStrings["Bdd_Handicap_Data"].ConnectionString;
            //System.Data.SqlClient.SqlConnection sqlConnection1 =
            //new System.Data.SqlClient.SqlConnection("Bdd_Handicap_Data");

            //System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            //cmd.CommandType = System.Data.CommandType.Text;
            //cmd.CommandText = "INSERT Region (RegionID, RegionDescription) VALUES (5, 'NorthWestern')";
            //cmd.Connection = sqlConnection1;

            //sqlConnection1.Open();
            //cmd.ExecuteNonQuery();
            //sqlConnection1.Close();

            /// <param name="weight">The weight of the dog.</param>
            /// <param name="name">The name of the dog.</param>
            /// <param name="breed">The breed of the dog.</param>


            //static void AddDog(int weight, string name, string breed)
            #endregion
            {
                using (SqlConnection con = new SqlConnection(
                HandicapsApp.Properties.Settings.Default.Bdd_Handicap_DataConnectionString))
                {
                    con.Open();
                    try
                    {
                        using (SqlCommand command = new SqlCommand(
                        "INSERT INTO handicap_Customer VALUES(@Customer_ID, @Customer_FirstName, @Customer_LastName, @Customer_Email, @Customer_Street, @Customer_ZipCode, @Customer_City, @Customer_Mileage, @Customer_Digicode, @Customer_PhoneNumber, @Customer_MobilePhone, @FK_Commercial_ID, @Customer_Pass, @Customer_Company)", con))
                        {
                            command.Parameters.Add(new SqlParameter("Customer_ID", guid));
                            command.Parameters.Add(new SqlParameter("Customer_FirstName", tbPrenom.Text));
                            command.Parameters.Add(new SqlParameter("Customer_LastName", tbNom.Text));
                            command.Parameters.Add(new SqlParameter("Customer_Email", tbEmail.Text));
                            command.Parameters.Add(new SqlParameter("Customer_Street", tbAdresse.Text));
                            command.Parameters.Add(new SqlParameter("Customer_ZipCode", tbCodePostal.Text));
                            command.Parameters.Add(new SqlParameter("Customer_City", tbVille.Text));
                            command.Parameters.Add(new SqlParameter("Customer_Mileage", tbKilo.Text));
                            command.Parameters.Add(new SqlParameter("Customer_Digicode", tbDigicode.Text));
                            command.Parameters.Add(new SqlParameter("Customer_PhoneNumber", tbTel.Text));
                            command.Parameters.Add(new SqlParameter("Customer_MobilePhone", tbPortable.Text));
                            command.Parameters.Add(new SqlParameter("FK_Commercial_ID", guid));
                            command.Parameters.Add(new SqlParameter("Customer_Pass", tbAdresse.Text));
                            command.Parameters.Add(new SqlParameter("Customer_Company", tbSociete.Text));

                            command.ExecuteNonQuery();

                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex);
                    }
                }
            }
        }


        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void handicap_CustomerBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            //this.Validate();
            //this.handicap_CustomerBindingSource.EndEdit();
            //this.tableAdapterManager.UpdateAll(this.Bdd_Handicap_DataDataSet);

            //    try
            //    {
            //        this.Validate();
            //        this.handicap_CustomerBindingSource.EndEdit();
            //        this.handicap_CustomerTableAdapter.Update(this.Bdd_Handicap_DataDataSet.handicap_Customer);
            //        MessageBox.Show("Mise à jour de la base de données effectuée.");
            //    }
            //    catch (System.Exception ex)
            //    {
            //        MessageBox.Show("Echec de la mise à jour de la base de données");
            //    }

            //}

            //private void newClient_Load(object sender, EventArgs e)
            //{
            //    // TODO: cette ligne de code charge les données dans la table 'Bdd_Handicap_DataDataSet.handicap_Customer'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
            //    this.handicap_CustomerTableAdapter.Fill(this.Bdd_Handicap_DataDataSet.handicap_Customer);
            //}
        }
    }
}
